package cn.spring.user;

import cn.spring.user.service.IUserService;
import cn.spring.user.service.UserServiceImpl;
import cn.springweb.domain.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: mayuanbao
 * @Date: 2018-11-23 14:20
 * @Description:
 */
public class UserServlet extends HttpServlet {
    private IUserService service;

    @Override
    public void init() throws ServletException {
        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
        service = ctx.getBean(IUserService.class);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("username");
        String pwd = req.getParameter("password");
        String realName = req.getParameter("realName");
        User user = new User();
        user.setUserName(name);
        user.setPassword(pwd);
        user.setRealName(realName);
        service.save(user);
    }

}
